// SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
// SPDX-License-Identifier: GPL-3.0-only

package service_impl

import "github.com/gin-gonic/gin"

func SendUnAuthError(c *gin.Context, message string) {
	c.Header("WWW-Authenticate", "Basic realm=\"open seaotter auth\"")
	c.JSON(401, &ErrorList{
		Errors: []Error{
			{
				Code:    ERROR_CODE_UNAUTHORIZED,
				Message: message,
			},
		},
	})
}

func SendError(c *gin.Context, httpCode int, errCode ERROR_CODE, message string) {
	c.JSON(httpCode, &ErrorList{
		Errors: []Error{
			{
				Code:    errCode,
				Message: message,
			},
		},
	})
}

func SendInvalidDigestError(c *gin.Context, message, digest string) {
	c.JSON(400, &ErrorList{
		Errors: []Error{
			{
				Code:    ERROR_CODE_DIGEST_INVALID,
				Message: message,
				Detail: map[string]string{
					"digest": digest,
				},
			},
		},
	})
}
